home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk125 / smarticon / src / hooks.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  2KB  |  68 lines

  1. #include <exec/types.h>
  2.  
  3. #ifndef DEBUG
  4. #include <proto/exec.h>
  5. #endif
  6.  
  7. typedef  LONG   (*PFL)();
  8.  
  9. extern   struct   ExecBase       *SysBase;
  10. extern   struct   IntuitionBase  *IntuitionBase;
  11. extern   LONG     OWentry_point(), CWentry_point(), MIentry_point(), PMentry_point();
  12. extern   VOID     MyOpenWindow(), MyCloseWindow(), MyPutMsg();
  13.  
  14. struct   RomHook
  15.    {
  16.    struct Library *hk_Base;
  17.    LONG            hk_SysFunc;
  18.    PFL             hk_MyFunc;
  19.    PFL             hk_Entry;
  20.    LONG            hk_LVO;
  21.    };
  22.  
  23. #define  NEWHOOKS 4
  24. struct   RomHook  Hook[NEWHOOKS] =
  25.    {
  26.       { NULL, 0, (PFL)MyOpenWindow,  (PFL)OWentry_point, -204 },
  27.       { NULL, 0, (PFL)MyCloseWindow, (PFL)CWentry_point,  -72 },
  28.       { NULL, 0, NULL,               (PFL)MIentry_point, -150 },
  29.       { NULL, 0, (PFL)MyPutMsg,      (PFL)PMentry_point, -366 },
  30.    };
  31.  
  32.  
  33. /* The SetHooks() and CleanHooks() functions set the parameters for     */
  34. /* the SetFunction() calls and execute those. By doing so, the          */
  35. /* libraries (namely Exec and Intuition) vector tables are patched so   */
  36. /* that calls to the specified functions go trough our code before or   */
  37. /* after doing their normal stuff.                                      */
  38. /* We must save the old pointers to restore them when exiting.          */
  39. /*                                                                      */
  40. /* This is derived from DropShadow's hooks.                             */
  41.  
  42. VOID
  43. SetHooks()
  44. {
  45.    register USHORT   h;
  46.  
  47.    Forbid();
  48.    for(h=0; h<NEWHOOKS; h++)
  49.       {
  50.       if (h<3) Hook[h].hk_Base = (struct Library *)IntuitionBase;
  51.       else     Hook[h].hk_Base = (struct Library *)SysBase;
  52.       Hook[h].hk_SysFunc = SetFunction(Hook[h].hk_Base,Hook[h].hk_LVO,Hook[h].hk_Entry);
  53.       }
  54.    Permit();
  55. }
  56.  
  57. VOID
  58. ClearHooks()
  59. {
  60.    register USHORT   h;
  61.  
  62.    Forbid();
  63.    for(h=0; h<NEWHOOKS; h++)
  64.       SetFunction(Hook[h].hk_Base, Hook[h].hk_LVO, Hook[h].hk_SysFunc);
  65.    Permit();
  66. }
  67.  
  68.